package com.free.semantic.infrastruct.mapper;

import com.free.semantic.infrastruct.common.ModelDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 模型Mapper接口
 */
@Mapper
public interface ModelMapper {
    
    @Select("SELECT * FROM model WHERE id = #{id}")
    ModelDO findById(@Param("id") Long id);
    
    @Select("SELECT * FROM model")
    List<ModelDO> findAll();
    
    @Select("SELECT * FROM model WHERE category = #{category}")
    List<ModelDO> findByCategory(@Param("category") String category);
    
    @Select("SELECT * FROM model WHERE publisher = #{publisher}")
    List<ModelDO> findByPublisher(@Param("publisher") String publisher);
    
    @Select("SELECT * FROM model WHERE semantic_network_id = #{semanticNetworkId}")
    ModelDO findBySemanticNetworkId(@Param("semanticNetworkId") Long semanticNetworkId);
    
    @Insert("INSERT INTO model(name, description, category, publisher, usage_count, semantic_network_id, create_time, update_time) " +
            "VALUES(#{name}, #{description}, #{category}, #{publisher}, #{usageCount}, #{semanticNetworkId}, NOW(), NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(ModelDO modelDO);
    
    @Update("UPDATE model SET name = #{name}, description = #{description}, " +
            "category = #{category}, publisher = #{publisher}, usage_count = #{usageCount}, " +
            "semantic_network_id = #{semanticNetworkId}, update_time = NOW() WHERE id = #{id}")
    int update(ModelDO modelDO);
    
    @Update("UPDATE model SET usage_count = usage_count + 1, update_time = NOW() WHERE id = #{id}")
    int incrementUsageCount(@Param("id") Long id);
    
    @Delete("DELETE FROM model WHERE id = #{id}")
    int deleteById(@Param("id") Long id);
} 